package com.sans.oop;

import org.junit.Test;

/**
 * @author Sans
 */
public class InterfaceClassTest {
    static class User{
        private String name;
        private Integer age;

        public String getName() {
            return name;
        }

        public Integer getAge() {
            return age;
        }

        public void setAge(Integer age) {
            this.age = age;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
    interface UserService{
        /**
         * 添加一个用户
         * @param user 用户信息
         */
        void insert(User user);

        /**
         * 按主键删除一个用户
         * @param id 编号
         */
        void deleteById(int id);

        /**
         * 按主键修改一个用户
         * @param id 编号
         */
        void updateById(int id);

        /**
         * 按主键查找一个用户
         * @param id 编号
         * @return 对应编号的用户信息
         */
        User selectById(int id);
    }
    static class UserServiceImpl implements UserService{

        @Override
        public void insert(User user) {
            System.out.println("添加成功...");
        }

        @Override
        public void deleteById(int id) {
            System.out.println("删除成功...");
        }

        @Override
        public void updateById(int id) {
            System.out.println("修改成功...");
        }

        @Override
        public User selectById(int id) {
            System.out.println("查询成功...");
            return null;
        }
    }
    @Test
    public void userService(){
        UserService userservice = new UserServiceImpl();
        userservice.insert(new User());
        userservice.deleteById(1);
        userservice.updateById(1);
        userservice.selectById(1);
    }
    static class Dog{
        private String name;
        private Integer age;

        public Integer getAge() {
            return age;
        }

        public void setAge(Integer age) {
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
    interface DogService{
        /**
         * 添加一只狗
         * @param dog 狗的信息
         */
        void insert(Dog dog);

        /**
         * 按主键删除一只狗
         * @param id 编号
         */
        void deleteById(int id);

        /**
         * 按主键修改一只狗
         * @param id 编号
         */
        void updateById(int id);

        /**
         * 按主键查询一只狗
         * @param id 编号
         * @return 对应编号的狗的信息
         */
        Dog selectById(int id);
    }
    static class DogServiceImpl implements DogService{

        @Override
        public void insert(Dog dog) {
            System.out.println("添加成功...");
        }

        @Override
        public void deleteById(int id) {
            System.out.println("删除成功...");
        }

        @Override
        public void updateById(int id) {
            System.out.println("修改成功...");
        }

        @Override
        public Dog selectById(int id) {
            System.out.println("查询成功...");
            return null;
        }
    }
    @Test
    public void DogService(){
        DogService dogservice = new DogServiceImpl();
        dogservice.insert(new Dog());
        dogservice.deleteById(1);
        dogservice.updateById(1);
        dogservice.selectById(1);
    }
    static class Cat{
        private String name;
        private Integer age;

        public Integer getAge() {
            return age;
        }

        public void setAge(Integer age) {
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
    interface CatService{
        /**
         * 添加一只猫
         * @param cat 猫的信息
         */
        void insert(Cat cat);

        /**
         * 按主键删除一只猫
         * @param id 编号
         */
        void deleteById(int id);

        /**
         * 按主键修改一只猫
         * @param id 编号
         */
        void updateById(int id);

        /**
         * 按主键查询一只猫
         * @param id 编号
         * @return 对应编号的猫的信息
         */
        Cat selectById(int id);
    }
    static class CatServiceImpl implements CatService{

        @Override
        public void insert(Cat cat) {
            System.out.println("添加成功...");
        }

        @Override
        public void deleteById(int id) {
            System.out.println("删除成功...");
        }

        @Override
        public void updateById(int id) {
            System.out.println("修改成功...");
        }

        @Override
        public Cat selectById(int id) {
            System.out.println("查询成功...");
            return null;
        }
    }
    @Test
    public void catService(){
        CatService catservice = new CatServiceImpl();
        catservice.insert(new Cat());
        catservice.deleteById(1);
        catservice.updateById(1);
        catservice.selectById(1);
    }
}
